/**
 * @author: mattwang@tencent.com
 * @date: 2012-10-10
 */

#ifndef __LDA_CORE__
#define __LDA_CORE__

#include <iostream>
#include <map>
#include <string>
#include <vector>

#include "simple_loader.h"

using namespace std;

class LDACore {
public:
	int train(SimpleLoader &data);
	void save_model();
	void load_model();
	int infer(SimpleLoader &data, string infer_result);

private:
	int sample();
	double compute_likelihood();
	int init_corpus(SimpleLoader &data);
	void free_corpus();
	int sync_model();

private:
	uint64_t *global_topic_distribution;
	uint64_t ** global_word_topic;
	uint64_t * global_word_topic_mem;

	uint64_t **all_doc_topic_distribution;
	int **all_doc_word_topic;
	int *doc_size;

	std::vector<std::vector<int> > *train_docs;

	int global_topic_num;
	int global_word_num;
	int local_doc_num;

	double *temp_distribution;

private:
};

#endif  // __LDA_CORE__
